import numpy as np
import sys
from PIL import Image
from utils import np2c_header, np_quant
from os import path
import shutil

#####################################################
IMG_DIR     = 'test_img'
OUTPUT_DIR  = path.join("..", "params")
#####################################################

def img2h(img_fname, output_file_name):
    img = Image.open(img_fname).convert("L").resize((32,32))
    input_data = np.array((255. - np.array(img))/255. * 2 - 1)
    input_data = np.expand_dims(input_data, 0)
    print(input_data.shape)
    np2c_header(np_quant(input_data), output_file_name)
    
if __name__ == "__main__":
    for i in range(10):
        img2h(path.join(IMG_DIR, str(i)+'.png'), 'img_in_' + str(i))
        shutil.move('img_in_{}.h'.format(i), path.join(OUTPUT_DIR, 'img_in_{}.h'.format(i)))
    
#     if not len(sys.argv)==2:
#         print("Usage: {} img_file".format(sys.argv[0]))
#         exit(0)
#     ########### run model ###########
#     img = Image.open(sys.argv[1]).convert("L").resize((32,32))
#     input_data = np.array((255. - np.array(img))/255. * 2 - 1)
#     input_data = np.expand_dims(input_data, 0)
#     print(input_data.shape)
#     np2c_header(input_data, "img_in")